package com.yjt.fresh.activity;

import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.yjt.fresh.R;
import com.yjt.fresh.base.BaseSimpleActivity;
import com.yjt.fresh.constant.MyConstants;
import com.yjt.fresh.utils.CommonsToolsHelper;
import com.yjt.fresh.widget.ClearEditText;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by UPC on 2018/8/18.
 */

public class AtyStoreSearch extends BaseSimpleActivity {
    @BindView(R.id.rl_app_aty_search_back)
    RelativeLayout mRlhBack;
    @BindView(R.id.edt_app_aty_search)
    ClearEditText mEdtSearch;
    @BindView(R.id.btn_app_aty_search_search)
    Button mBtnSearch;

    @Override
    protected int getContentView() {
        return R.layout.app_aty_store_search;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
        CommonsToolsHelper.setEditTextInputSpace(mEdtSearch);
    }

    @Override
    protected void initEvent() {
        mEdtSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.toString().length() > 0){
                    mBtnSearch.setClickable(true);
                    mBtnSearch.setBackgroundResource(R.drawable.selector_43b624_3b9f20_100);
                }else {
                    mBtnSearch.setClickable(false);
                    mBtnSearch.setBackgroundResource(R.drawable.shape_f0f0f0_100);
                }
            }
        });

        mBtnSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, AtyProducts.class);
                intent.putExtra(MyConstants.PRODUCT_KEY_WORD, mEdtSearch.getText().toString());
                intent.putExtra(MyConstants.STORE_ID,getIntent().getStringExtra(MyConstants.STORE_ID));
                intent.putExtra(MyConstants.SEARCH_OR_CATEGORY,MyConstants.SEARCH);
                startActivity(intent);
            }
        });

        mRlhBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        mBtnSearch.setClickable(false);
        mBtnSearch.setBackgroundResource(R.drawable.shape_f0f0f0_100);
    }
}
